<template>
  <div>
    <city-header></city-header>
    <city-search :cities="cities"></city-search>
    <city-list :cities="cities" :hotCities="hotCities" :letter="letter"></city-list>
    <city-alphabet :cities="cities" @change="handleClickLetter"></city-alphabet>
  </div>
</template>

<script>
import axios from 'axios'
import cityHeader from './components/cityHeader'
import citySearch from './components/CitySearch'
import cityList from './components/cityList'
import CityAlphabet from './components/Alphabet'
export default {
  name: 'City',
  components: {
    cityHeader,
    citySearch,
    cityList,
    CityAlphabet
  },
  data () {
    return {
      cities: {},
      hotCities: [],
      letter: ''
    }
  },
  methods: {
    getCityInfo () {
      axios.get('api/city.json')
        .then(this.getCityInfoSucc)
    },
    getCityInfoSucc (res) {
      const result = res.data
      if (result.ret && result.data) {
        const data = result.data
        this.cities = data.cities
        this.hotCities = data.hotCities
      }
    },
    handleClickLetter (letter) {
      this.letter = letter
    }
  },
  mounted () {
    this.getCityInfo()
  }
}
</script>

<style lang="stylus" scoped>

</style>
